require "test/unit"
class Test_Koans<Test::Unit::TestCase
  def test_non_parallel_assignment
    names = ["John", "Smith"]
    assert_equal ["John", "Smith"], names
  end

  def test_parallel_assignments
    first_name, last_name = ["John", "Smith"]
    assert_equal "John", first_name
    assert_equal "Smith", last_name 
  end

  def test_parallel_assignments_with_extra_values
    first_name, last_name = ["John", "Smith", "III"]
    assert_equal "John", first_name
    assert_equal "Smith", last_name  
  end            #在first_name last_name 等于再里面取值，赋值的含义，

  def test_parallel_assignments_with_splat_operator
    first_name, *last_name =  ["John", "Smith", "III"]
    assert_equal "John",            first_name
    assert_equal ["Smith", "III"],   last_name
  end   # *last_name的含义，将后面所有元素作为一个整体赋值给last_name

  def test_parallel_assignments_with_too_few_variables
    first_name, last_name = ["Cher"]
    assert_equal "Cher",     first_name
    assert_equal  nil,       last_name
  end    #array中只有一个元素，first_name占有，故last_name 为空，nil

  def test_parallel_assignments_with_subarrays
    first_name, last_name = [["Willie", "Rae"], "Johnson"] 
    assert_equal ["Willie", "Rae"],     first_name
    assert_equal "Johnson",             last_name
  end  #array中包含array就将其作为一个分支，单独作为一个元素，所有first_name 就为分支的array
 
  def test_parallel_assignment_with_one_variable
    first_name, = ["John", "Smith"]
    assert_equal "John", first_name
  end     #只赋值了first_name， 故为"John"
 
  def test_swapping_with_parallel_assignment
    first_name = "Roy"
    last_name = "Rob"
    first_name, last_name = last_name, first_name
    assert_equal "Rob",   first_name
    assert_equal "Roy",   last_name 
  end
  #首先给first_name， last_name赋值，  然后将last_name作为第一个元素，first_name作为第二个元素组成一个array,再重新个first_name，last_name 进行赋值
 
end
